<template>
 <el-container class="home-container">
    <el-header>
        <div class="imgtext">
            <img src="../assets/img/bglogo.png" alt="">
            <span>电商后台管理系统</span>
        </div>
        <el-button type="danger" plain @click="backlogin">退出</el-button>
    </el-header>
    <el-container>
        <el-aside :width="isCollapse?'64px':'200px'">
            <div class="toggle-button" @click="toggleCollapse">|||</div>
            <el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF" unique-opened :collapse="isCollapse"
            :router="true" :default-active='activepath'
            :collapse-transition="false">
                <el-submenu :index="item.id+''" v-for="(item) in meaulists" :key="item.id">
                    <template slot="title">
                        <i :class="font[item.id]"></i>
                        <span>{{item.authName}}</span>
                    </template>  
                    <el-menu-item :index="'/'+items.path+''" v-for="items in item.children" :key="items.id" @click="saveNavstate('/'+items.path)">
                        <template slot="title">
                            <i class="el-icon-menu"></i>
                            <span>{{items.authName}}</span>
                        </template>  
                    </el-menu-item>        
                </el-submenu>
            </el-menu>
        </el-aside>
        <el-main>
            <router-view></router-view>
        </el-main>
    </el-container>
</el-container>
  
</template>

<script>
export default {
    created() {
        this.getmeanlist()
        this.activepath = window.sessionStorage.getItem("activepath")
    },
   data() {
       return {
           isCollapse:false,
           activepath:'',
           meaulists:[],
           font:{
               '125':'iconfont icon-subscriber-square',
               '103':'iconfont icon-icon-quanxian',
               '101':'iconfont icon-shangpin1',
               '102':'iconfont icon-xingzhuanggongnengtubiao-',
               '145':'iconfont icon-shujux'
               }
       }
   },
    methods: {
        backlogin(){
            window.sessionStorage.clear()
            this.$router.push('/')
        },
       async getmeanlist(){
           const {data:res} = await this.$http.get('menus')
           
           if(res.meta.status!=200) return this.$message.error(res.meta.msg);
           this.meaulists = res.data
        },
        toggleCollapse(){
           this.isCollapse=!this.isCollapse
        },
        saveNavstate(activepath){
            window.sessionStorage.setItem('activepath',activepath)
            this.activepath = activepath
        }
    },
}
</script>

<style scoped>
.home-container{
    height: 100%;
}

.el-header{
    background-color: #373D41;
    display: flex;
    justify-content:space-between;
    padding-left: 0;
    align-items: center;
}
.el-aside{
    background-color: #333744;
}
.el-aside .toggle-button{
    background-color: #4A5064;
    color: #fff;
    text-align: center;
    font-size: 10px;
    line-height: 24px;
    letter-spacing: 0.2em;
    cursor: pointer;
}
.el-aside .el-menu{
    border-right: 0px;
}
.el-main{
    background-color: #eaedf1;
}
.imgtext{
    display: flex;
    align-items: center;
}
.imgtext img{
    width: 50px;
    height: 50px;
}
.imgtext span{
    color:#fff;
    margin-left: 15px;
    font-size: 20px;
}
.iconfont{
    margin-right: 10px;
}
</style>